<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 零度  <2109877665@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2019年08月20日
// +----------------------------------------------------------------------

include("../Core/Common.php");
if($islogin_user==1){}else exit("<script language='javascript'>window.location.href='./Social.php';</script>");
$act=$_GET['act'];
/*
if($act=='Login'){//登录商户
	$pid=daddslashes($_POST['pid']);
	$key=daddslashes($_POST['key']);
	$userrow=$DB->query("SELECT * FROM pay_daili WHERE pid='{$pid}' limit 1")->fetch();
		if(!$pid or !$key){
			$result=array("code"=>-1,"msg"=>"所有参数不能为空");
		}elseif($pid==$userrow['pid'] && $key==$userrow['key']) {
			$session=md5($userrow['pid'].$key.$password_hash);
			$expiretime=time()+604800;
			$token=authcode("{$userrow['pid']}\t{$session}\t{$expiretime}", 'ENCODE', $conf['KEY']);
			setcookie("daili_token", $token, time() + 604800);
			$result=array("code"=>1,"msg"=>"登录成功");
		}elseif($admin_pass != $conf['admin_pass']) {
			$_SESSION['pass_error']++;
			$result=array("code"=>-1,"msg"=>"登录失败");
		}
}elseif($act=='Add_check'){//添加授权	
	$url= $_POST['url'];
	$qq= $_POST['qq'];
	$ip= $_POST['ip'];
	$money= $_POST['money'];
	$beizhu= $_POST['beizhu'];
    $pid= $_POST['pid'];
	$key= $_POST['key'];
	$is=$DB->query("SELECT * FROM `pay_check` WHERE `qq`='{$qq}' limit 1")->fetch();
	if($is){
		$pid= $is['pid'];
		$key= $is['key'];
		$authcode=$is['authcode'];
	}else{
		$authcode=md5(mt_rand(1000000000,9999999999).$qq);
	}
	if($userrow['nums']>=1){
		$sds=$DB->exec("INSERT INTO `pay_check` (`daili_id`,`url`,`qq`, `money`,`beizhu`,`authcode`,`addtime`) VALUES ('{$userrow['pid']}','{$url}','{$qq}','{$money}','{$beizhu}','{$authcode}','{$date}')");
		if($sds){
		$is=$DB->query("SELECT * FROM `pay_cloud` WHERE `qq`='{$qq}' limit 1")->fetch();
			if(!$is){
				$pid= '1'.mt_rand(10000000,99999999);
				$key= '1'.mt_rand(10000000,99999999);
				$sds=$DB->exec("INSERT INTO `pay_cloud` (`qq`,`pid`,`key`) VALUES ('{$qq}','{$pid}','{$key}')");
			}
		}elseif($sds){
			$DB->exec("update `pay_daili` set `nums` =`nums`-'1' where pid='{$userrow['pid']}'");
			$result=array("code"=>1,"msg"=>"添加授权成功");
		}else{
			$result=array("code"=>1,"msg"=>"添加授权成功,但生成云端账号密码失败");
		}
	}else{
		$result=array("code"=>-1,"msg"=>"添加授权失败,授权额度不足");
	}
}else*/if($act=='Edit_check'){	//修改授权
	$id= $_POST['id'];
	$url= $_POST['url'];
	$is=$DB->query("SELECT * FROM `pay_check` WHERE `id`='{$id}' limit 1")->fetch();
	if(!$is){
		$result=array("code"=>-2,"msg"=>"此授权记录不存在");
	}elseif($is['qq']!=$userrow['qq']){
		$result=array("code"=>-2,"msg"=>"此授权记录并非你旗下,请勿乱操作");
	}else{
		$sqs=$DB->exec("update `pay_check` set `url`='{$url}' where id='{$id}'");
		if($sqs){
			$result=array("code"=>1,"msg"=>"修改授权成功");
		}else{
			$result=array("code"=>-1,"msg"=>"修改授权失败");
		}
	}
}else/*if($act=='Status_check'){//禁封/解封授权
	$id=daddslashes($_POST['id']);
	$is=$DB->query("SELECT * FROM `pay_check` WHERE `id`='{$id}' limit 1")->fetch();
		if(!$is){
			$result=array("code"=>-2,"msg"=>"此授权记录不存在");
		}elseif($is['user_id']!=$userrow['pid']){
			$result=array("code"=>-2,"msg"=>"此授权记录并非你旗下,请勿乱操作");
		}else{
			if($is['status']==1){
				$msg_a = '禁封授权成功';
				$msg_b = '禁封授权失败';
				$sqs=$DB->exec("update `pay_check` set `status`='0' where qq='{$is['qq']}'");
			}else{
				$msg_a = '此授权可能违规,无法解封授权。';
				$msg_b = '解封授权失败';
				//$DB->exec("DELETE FROM `pay_ip_check` WHERE `url`='{$is['url']}'");
				//$sqs=$DB->exec("update `pay_check` set `status`='1', `ip`='' where qq='{$is['qq']}'");
			}
			if($sqs){
				$result=array("code"=>1,"msg"=>$msg_a);
			}else{
				$result=array("code"=>-1,"msg"=>$msg_b);
			}
		}
}else*/{
	$result=array("code"=>-9,"msg"=>"参数错误");
}
if($result)
	exit(json_encode($result));
else
	exit($data);
?>